package com.zrkj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zrkj.entity.Marketing;
import com.zrkj.entity.vo.Result;
import com.zrkj.service.IMarketingService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
/**
 * @author : 司总
 * @className : MarketingController
 * @package: com.zrkj.controller
 * @description : 营销活动表 前端控制器
 * @date :  2023-11-23
 */
@RestController
@RequestMapping(value = "/marketing")
@Api(tags = "营销活动表")
public class MarketingController {
private final IMarketingService imarketingService;

public MarketingController(IMarketingService imarketingService){
        this.imarketingService=imarketingService;
        }

/**
 * 添加
 *
 * @param marketing
 * @return
 */
@PostMapping("/add")
public Result<String> add(@RequestBody Marketing marketing){
        return imarketingService.add(marketing);
        }

/**
 * 更新
 *
 * @param marketing
 * @return
 */
@PutMapping(value = "/update")
public Result<Boolean> update(@RequestBody Marketing marketing){
        return imarketingService.update(marketing);
        }

/**
 * 删除
 *
 * @param ids
 * @return
 */
@DeleteMapping(value = "/delete")
public Result<Boolean> delete(@RequestParam(value = "ids") String ids){
        String[]idsArray=ids.split(",");
        List<String> idList=new ArrayList<>();
        for(String id:idsArray){
        idList.add(id);
        }
        return imarketingService.delete(idList);
        }

/**
 * 查询详情
 *
 * @param id
 * @return
 */
@GetMapping(value = "/getById/{id}")
public Result<Marketing> getById(@PathVariable(value = "id") String id){
        return imarketingService.getById(id);
        }

/**
 * 查询列表
 *
 * @param marketing
 * @return
 */
@PostMapping(value = "/queryList")
public Result<List<Marketing>>queryList(@RequestBody Marketing marketing){
        return imarketingService.queryList(marketing);
        }

/**
 * 查询分页列表
 *
 * @param marketing
 * @return
 */
@PostMapping(value = "/queryPageList")
public Result<IPage<Marketing>>queryPageList(@RequestBody Marketing marketing){
        return imarketingService.queryPageList(marketing.getPage(), marketing);
        }
        }
